package com.jxc.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/AddSum2")
public class AddSum2 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String add1 = req.getParameter("add1");
        String add2 = req.getParameter("add2");

        int n1 =Integer.parseInt(add1);
        int n2 = Integer.parseInt(add2);
        int result = n1 + n2;

        // 注意result是int类型的，所以在另一个servlet get的时候用int来接收
        req.setAttribute("result",result);
        req.getRequestDispatcher("/PrintSum").forward(req,resp);

    }
}
